package com.pepository.neo4j;

import com.model.neo4j.Movie;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;

public interface MovieRepository extends Neo4jRepository<Movie, Long> {

    Movie findByTitle(@Param("title") String title);

    Collection<Movie> findByTitleLike(@Param("title") String title);

    // 使用Cypher语句 编写用户自定义 方法
    @Query(
            "MERGE (m:Movie{title:$title})" +
            "MERGE (p:Person{name:$name})" +
            "MERGE (m)<-[a:ACTED_IN]-(p)" +
            "SET a.mode=$mode, a.pay=$pay RETURN m"
    )
    Movie createGraph(@Param("title") String title,@Param("name") String name, @Param("mode")String mode, @Param("pay") long pay);

    @Query(
            "MATCH (m:Movie {title:$title})<-[roles:ACTED_IN]-(person:Person)" +
            "RETURN m, roles, person"
    )
    Movie getGraphByTitle(@Param("title") String title);
}
